package com.wzh.borrow.controller;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

import com.wzh.borrow.vo.Rate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.wzh.borrow.entity.UserEntity;
import com.wzh.borrow.service.UserService;
import com.wzh.common.utils.PageUtils;
import com.wzh.common.utils.R;



/**
 * 
 *
 * @author wzh
 * @email 1281204121@qq.com
 * @date 2022-01-27 21:23:52
 */
@RestController
@RequestMapping("borrow/user")
public class UserController {
    @Autowired
    private UserService userService;

    @Autowired
    private RedisTemplate redisTemplate;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = userService.queryPage(params);
        ArrayList<Rate> rate= (ArrayList<Rate>) redisTemplate.boundHashOps("map").get("rate");
        return R.ok().put("page", page).put("rate",rate);
    }

    /**
     * 列表
     */
    @RequestMapping("/login")
    public R login(@RequestParam Map<String, Object> params){
        return userService.login(params);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{tel}")
    public R info(@PathVariable("tel") Integer tel){
		UserEntity user = userService.getById(tel);

        return R.ok().put("user", user);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody UserEntity user){
		userService.save(user);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody UserEntity user){
		userService.updateById(user);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] tels){
		userService.removeByIds(Arrays.asList(tels));

        return R.ok();
    }

}
